package com.allwees.support.payment.paypal.builder;

import com.paypal.payments.CapturesRefundRequest;
import com.paypal.payments.Money;
import com.paypal.payments.RefundRequest;
import com.allwees.support.payment.model.RefundInfo;

import java.math.BigDecimal;

public class RefundRequestBuilder {

    public static CapturesRefundRequest build(RefundInfo refundInfo) {
        return new CapturesRefundRequest(refundInfo.getPaymentNo())
                .prefer("return=representation")
                .requestBody(buildRequest(refundInfo.getCurrency(), refundInfo.getAmt()));
    }

    private static RefundRequest buildRequest(String currency, BigDecimal amt) {
        return new RefundRequest().
                amount(new Money()
                        .currencyCode(currency)
                        .value(amt.toPlainString())
                );
    }
}
